package org.touch.server;

import java.util.HashMap;
import java.util.Map;

import org.touch.util.StringUtils;

public class ListenerFactory {
	
	private static ListenerFactory factory;

	private Map<Integer, Listener> listeners = new HashMap<Integer, Listener>();
	
	private ListenerFactory(){
		register(new SimpleListener(0));
	}
	
	
	public Task parseTask(String str){
		if(StringUtils.isNotEmpty(str)){
			
		}
		return null;
	}
	
	public static ListenerFactory getInstance(){
		if(factory == null){
			factory = new ListenerFactory();
		}
		return factory;
	}
	
	public void register(Listener listener){
		listeners.put(listener.getAction(), listener);
	}
	
	public void execute(Task task){
		if(listeners.containsKey(task.getAction())){
			listeners.get(task.getAction()).execute(task);
		}
	}
}
